#include <osg/Geode>
#include <osg/ShapeDrawable>
#include <osg/Group>
#include <osgViewer/Viewer>
#include <osg/Notify>
#include <iostream>
#include <osg/DisplaySettings>

int main(int argc, char **argv)
{
        // 启用调试输出
    osg::setNotifyLevel(osg::DEBUG_INFO);
        // 设置显示设置，强制使用软件渲染作为后备方案
    osg::DisplaySettings::instance()->setNumMultiSamples(0);
    osg::DisplaySettings::instance()->setMinimumNumStencilBits(0);
    
    osgViewer::Viewer viewer;
        // 设置线程模型为单线程，避免多线程问题
    viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
    
        // 先运行一次初始化
    // viewer.realize();
    osg::ref_ptr<osg::ShapeDrawable> cube = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0.0f, 0.0f, 0.0f), 1.0f));
    osg::ref_ptr<osg::Geode> geode = new osg::Geode();
    geode->addDrawable(cube.get());

    osg::ref_ptr<osg::Group> root = new osg::Group();
    root->addChild(geode);
    int number = root->getNumChildren();
    auto childNode = root->getChild(0);
    viewer.setSceneData(root);
     // 添加返回值检查c
    try {
        return viewer.run();
    } catch (const std::exception& e) {
        std::cerr << "Exception caught: " << e.what() << std::endl;
        return -1;
    }
}